
package com.sausageking.client.merchant.activity;

import java.util.Date;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.inject.Inject;
import com.sausageking.client.MerchantServiceAsync;
import com.sausageking.client.merchant.ui.CodeView;
import com.sausageking.client.mvp.BaseActivity;
import com.sausageking.shared.YearPassCodes;

public class CodeActivity extends BaseActivity implements CodeView.Presenter {

  @Inject
  private CodeView view;

  @Inject
  private MerchantServiceAsync service;

  @SuppressWarnings("deprecation")
  private void loadPassCodeBook() {
    service.getPassCodeBook(getToken(),
        new Date().getYear() + 1900,
        new AsyncCallback<YearPassCodes>() {

          @Override
          public void onSuccess(YearPassCodes book) {
            view.setPassCodeBook(book);
          }

          @Override
          public void onFailure(Throwable caught) {
            Window.alert(caught.getLocalizedMessage());
          }
        });
  }

  @Override
  public String mayStop() {
    return null;
  }

  @Override
  public void print() {

  }

  @Override
  protected void startActivity(AcceptsOneWidget container, EventBus eventBus) {
    view.setPresenter(this);
    container.setWidget(view.asWidget());
    loadPassCodeBook();
  }
}
